﻿using UnityEngine;
using System.Collections.Generic;
using ProtoBuf.Message;

namespace UI
{
  

    public class UIFieldRunMapLineInfo : MonoBehaviour
    {
        const string icon0 = "UI_yewai_item_kongxian";
        const string icon1 = "UI_yewai_item_manglu";

        const string text0 = "UI_yewai_kongxian_kongxian";
        const string text1 = "UI_yewai_word_manglu";
        

        public UISprite stateIcon;
        public UISprite stateText;
        public UILabel line;
        public GameObject selected;

        UIFieldRunMapChangeLine changeLine;
        LineInfo lineInfo;

        public void Init(LineInfo lineInfo, UIFieldRunMapChangeLine changeLine)
        {
            this.changeLine = changeLine;
            this.lineInfo = lineInfo;
            selected.SetActive(lineInfo.line == StaticData.currLine);
            stateIcon.spriteName = lineInfo.state != 2 ? icon0 : icon1;
            stateText.spriteName = lineInfo.state != 2 ? text0 : text1;

            line.text = string.Format(TableTextBlo.GetText("field_line"), lineInfo.line);
        }

        public void OnClickLine()
        {
            StaticData.currLine = lineInfo.line;
            foreach(var obj in changeLine.lines)
            {
                var scripts = obj.GetComponent<UIFieldRunMapLineInfo>();
                scripts.selected.SetActive(false);
            }

            selected.SetActive(true);
        }
    }
}